package com.jklan.zhiqibackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jklan.zhiqibackend.common.ErrorCode;
import com.jklan.zhiqibackend.entity.PersonalRepositories;
import com.jklan.zhiqibackend.exception.BusinessException;
import com.jklan.zhiqibackend.service.PersonalRepositoriesService;
import com.jklan.zhiqibackend.mapper.PersonalRepositoriesMapper;
import org.springframework.stereotype.Service;

/**
 * @author 30688
 * @description 针对表【personal_repositories(个人仓库表)】的数据库操作Service实现
 * @createDate 2025-11-06 15:44:37
 */
@Service
public class PersonalRepositoriesServiceImpl extends ServiceImpl<PersonalRepositoriesMapper, PersonalRepositories>
        implements PersonalRepositoriesService {


    @Override
    public boolean createPersonalRepository(Long id) {
        // 检查用户是否已存在仓库
        if (baseMapper.selectCount(new LambdaQueryWrapper<>(PersonalRepositories.class).eq(PersonalRepositories::getOwnerId, id)) > 0) {
            throw new BusinessException(ErrorCode.REPO_CREATE_FAILED);
        }
        //创建个人仓库
        PersonalRepositories personalRepositories = new PersonalRepositories();
        personalRepositories.setOwnerId(id);
        int insert = baseMapper.insert(personalRepositories);
        return insert > 0;
    }
}




